#ifdef __WINDOWS__
#include <windows.h>
#endif
#include "DB/mysql.h"
#include "DB.h"
#include "Log.h"
#include "Xml.h"

DataBase::DataBase()
{
	m_pMysql = NULL;
}

DataBase::~DataBase()
{
	if ( m_pMysql )
		mysql_close(m_pMysql);
}

bool DataBase::Init( char* pIp, uint uPort, char* pUser, char* pPassWord, char* pDataBase )
{
	LogPrintf(LOGINFO, "DataBase::Init mysql_get_client_info : %s", mysql_get_client_info());
	m_pMysql = mysql_init(NULL);
	if ( m_pMysql == NULL )
		ProccessError(LOGERROR, "mysql_init", false);
	if ( mysql_real_connect(m_pMysql, pIp, pUser, pPassWord, pDataBase, uPort, NULL, 0) == NULL )
		ProccessError(LOGERROR, "mysql_real_connect", false);
	return true;
}

void DataBase::Close()
{
	if ( m_pMysql ){
		mysql_close(m_pMysql);
		m_pMysql = NULL;
	}
}

bool DataBase::ExecuteSql(const char* pSql, size_t len )
{
	if ( !pSql || len == 0 )
		return false;
	if ( mysql_real_query(m_pMysql, pSql, len) )
		ProccessError(LOGERROR, "mysql_real_query", false);
	return true;
}

bool DataBase::GetTablesInfo( Xml& xml )
{
	
	return true;
}
